package myPetStore.web.servlet;

import myPetStore.domain.Account;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class SignOutServlet extends HttpServlet {

    //检查是否登录了
    private static final String  SIGN_ON_FORM="/WEB-INF/jsp/account/signon.jsp";

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session=req.getSession();
        Account loginAccount=(Account) session.getAttribute("loginAccount");
        if(loginAccount==null){
            resp.sendRedirect(SIGN_ON_FORM);
        }else{
            session.removeAttribute("loginAccount");
            resp.sendRedirect("mainForm");
        }
    }
}
